package logic

import (
	"context"
	"zhihu-new/zhihurpc/zhihurpcclient"

	"zhihu-new/api/internal/svc"
	"zhihu-new/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForgetPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewForgetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgetPasswordLogic {
	return &ForgetPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ForgetPasswordLogic) ForgetPassword(req *types.ForgetPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	forgetPassword, err := l.svcCtx.ZhiHuRpc.ForgetPassword(l.ctx, &zhihurpcclient.ForgetPasswordRequest{
		Mobile:      req.Mobile,
		CaptSms:     req.CaptSms,
		Password:    req.Password,
		PasswordNew: req.PasswordNew,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "密码修改成功",
		Code:    200,
		Data:    forgetPassword,
	}, nil
}
